# Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution(object):
    def preorderTraversal(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        values = []
        if root is None:
            return values
        values.append(root.val)
        left_values = self.preorderTraversal(root.left)
        if left_values is not []:
            values = values + left_values
        right_values = self.preorderTraversal(root.right)
        if right_values is not []:
            values = values + right_values
        return values
